package com.tianma315.admin.qa.controller;


import java.util.Arrays;
import java.util.Date;

import com.tianma315.admin.common.base.BaseController;
import com.tianma315.admin.common.utils.Result;
import com.tianma315.admin.qa.vo.QaCheckVO;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.tianma315.admin.qa.domain.QaCheckDO;
import com.tianma315.admin.qa.service.QaCheckService;

/**
 * 
 * <pre>
 * 品控检查
 * </pre>
 * <small> 2019-07-09 16:02:56 | wen</small>
 */
@Controller
@RequestMapping("/qa/qaCheck")
public class QaCheckController extends BaseController{
	@Autowired
	private QaCheckService qaCheckService;
	
	@GetMapping()
	@RequiresPermissions("qa:qaCheck:qaCheck")
	String QaCheck(){
	    return "qa/qaCheck/qaCheck";
	}
	
	@ResponseBody
	@GetMapping("/list")
	@RequiresPermissions("qa:qaCheck:qaCheck")
	public Result<Page<QaCheckVO>> list(Integer pageNumber, Integer pageSize, QaCheckVO qaCheckDTO ,Date beginDate,
										Date endDate){
		// 查询列表数据
        Page<QaCheckVO> page = qaCheckService.getQaCheckPage(pageNumber,pageSize,qaCheckDTO,beginDate,endDate);
        return Result.ok(page);
	}
	
	@GetMapping("/add")
	@RequiresPermissions("qa:qaCheck:add")
	String add(){
	    return "qa/qaCheck/add";
	}

	@GetMapping("/edit/{qaCheckId}")
	@RequiresPermissions("qa:qaCheck:edit")
	String edit(@PathVariable("qaCheckId") Integer qaCheckId,Model model){
		QaCheckDO qaCheck = qaCheckService.selectById(qaCheckId);
		model.addAttribute("qaCheck", qaCheck);
	    return "qa/qaCheck/edit";
	}
	
	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	@RequiresPermissions("qa:qaCheck:add")
	public Result<String> save( QaCheckDO qaCheck){
		qaCheck.setCheckBy(getUserId());
		qaCheck.setCreateBy(getUserId());
		if(qaCheckService.addQaCheckDO(qaCheck)){
			return Result.ok();
		}
		return Result.fail();
	}
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("qa:qaCheck:edit")
	public Result<String>  update( QaCheckDO qaCheck){
		qaCheckService.updateById(qaCheck);
		return Result.ok();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	@RequiresPermissions("qa:qaCheck:remove")
	public Result<String>  remove( Integer qaCheckId){
		if(qaCheckService.deleteQaCheckDO(qaCheckId)){
            return Result.ok();
		}
		return Result.fail();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	@RequiresPermissions("qa:qaCheck:batchRemove")
	public Result<String>  remove(@RequestParam("ids[]") Integer[] qaCheckIds){
		for (Integer id: qaCheckIds) {
			qaCheckService.deleteQaCheckDO(id);
		}
		return Result.ok();
	}
	
}
